import time
from selenium import webdriver
from selenium.webdriver import ChromeOptions

option = ChromeOptions()
option.add_experimental_option('excludeSwitches',['enable-automation'])
option.add_experimental_option('useAutomationExtension',False)
driver = webdriver.Chrome(options=option)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument",{'source':'Object.defineProperty(navigator,"webdriver",{get:()=>undefind})'})
driver.get("https://www.baidu.com")

driver.find_element_by_id("kw").send_keys("零之使魔")
driver.find_element_by_id("su").click()

# 手动设置浏览器窗口大小(宽,高)
driver.set_window_size(800,800)
time.sleep(3)

# 设置浏览器窗口最大化
driver.maximize_window()
time.sleep(3)

# 浏览器后退 (相当于浏览器左上角的<-)
driver.back()
time.sleep(3)

# 浏览器前进 (相当于浏览器左上角的->)
driver.forward()
time.sleep(3)

# 控制浏览器滚动条
# 让滚动条到浏览器底端
js1 = "var q = document.documentElement.scrollTop=10000"
driver.execute_script(js1)
time.sleep(3)
# 让滚动条到浏览器顶端
js2 = "var q = document.documentElement.scrollTop=0"
driver.execute_script(js2)

time.sleep(3)
driver.quit()